﻿using AutoMapper;
using BPMN.Application.IService;
using BPMN.Domain.Entity.User;
using BPMN.DomianShare;
using Microsoft.AspNetCore.Mvc;
using BPMN.Application.Contracts.DTO.Request.Role;
using BPMN.Application.Contracts.DTO.Request.PerRole;
using BPMN.Application.Contracts.DTO.Response.RolePermission;
using BPMN.Application.Contracts.DTO.Response;

namespace BPMN.WebApi.Controllers
{
    /// <summary>
    /// 角色
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly IRoleAppService AppRole;
        public RoleController(IRoleAppService AppRole)
        {
            this.AppRole = AppRole;
        }
        /// <summary>
        ///  角色添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddRole(RoleRequstDto entity)
        {
            return Ok(await AppRole.AddRole(entity));
        }
        /// <summary>
        /// 角色显示功能
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRole()
        {
            return Ok(await AppRole.GetRole());
        }
        /// <summary>
        /// 根据Id获取角色信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRoleById(int Id)
        {
            return Ok(await AppRole.GetRoleById(Id));
        }
        /// <summary>
        /// 修改功能
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateRole(RoleRequstDto entity)
        {
            return Ok(await AppRole.UpdateRole(entity));
        }
        /// <summary>
        /// 删除功能
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> RoleDel(int Id)
        {
            return Ok(await AppRole.Delete(Id));
        }
        /// <summary>
        /// 角色权限表添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddRolePermission(PermissionRoleRequstDtoTwo entity)
        {
            return Ok(await AppRole.AddRolePer(entity));
        }

        /// <summary>
        /// 反填权限
        /// </summary>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetRolePermissionByRoleId(int RoleId)
        {
            return Ok(await AppRole.GetRolePermissionByRoleId(RoleId));
        }
        /// <summary>
        /// 添加自定义字段
        /// </summary>
        /// <param name="extend"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddExtend(Extend extend)
        {
            return Ok(await AppRole.AddExtend(extend));
        }
        /// <summary>
        /// 显示要使用的单元属性
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetAttrbutes()
        {
            return Ok(AppRole.GetAttrbutes());
        }
        /// <summary>
        /// 添加单元属性内容
        /// </summary>
        /// <param name="attr"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Addattribute(Attributes attr)
        {
            return Ok(AppRole.Addattribute(attr));
        }
        [HttpGet]
        public async Task<IActionResult> GetExtend()
        {
            return Ok(AppRole.GetExtend());
        }
    }
}
